﻿@model IEnumerable<FCNS.ERP.Models.ErpCost>

@{
    ViewBag.Title = "定义费用项目";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
 <input  id="existCost"  type="hidden" value=@ViewData["CostString"] />
<input id="RoomIOid" type="hidden" value=@ViewData["RoomIOid"] />

<script type="text/javascript">
    $(document).ready(function () {
        //设置已存在的项目
        var allCost = [];
        var allCostValue = [];
        var costString = $("#existCost").val().split(';');
        for (var i = 0; i < costString.length; i++)
        {
            allCost.push(costString[i].split(':')[0]);
            allCostValue.push(costString[i].split(':')[1]);
        }

        $(":checkbox").each(function () {
            var index = $.inArray($(this).next().val(), allCost)
            if (index == -1)//这里不行
            {
                $(this).prop("checked", false);
            }
            else
            {
                $(this).prop("checked", true);
                $(this).parent().next().next().next().next().next().children().val(allCostValue[index]);
                $(this).parent().next().next().next().next().next().children().attr("disabled", "disabled");
            }
        });

        $(":button").click(function () {
            var cString = "";
            $(":checkbox").each(function () {
                if ($(this).prop("checked") == true)
                {
                    cString += ($(this).next().val() + ":" + $(this).parent().next().next().next().next().next().children().val() + ";");
                }
            });

            window.location.replace("/House/TroomCostEditSubmit/" + $("#RoomIOid").val() + "?costString=" + cString);
        });
    });
</script>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Enable)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.UnitId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Summary)
        </th>
        <th>刻度/值</th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            <input checked="checked"   id="Enable" name="Enable" type="checkbox" value="true" />
            @Html.HiddenFor(modelItem => item.Id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Unit.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Price)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Summary)
        </td>
        <td>
            <input type="number" name="InitValue" id="InitValue" min="0" value="0" />
        </td>
    </tr>
}

</table>

<div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <input type="button" value="保存" class="btn btn-default" />
    </div>
</div>
